import { createRouter, createWebHistory } from "vue-router";
import notfound from "@/components/404";
const routes = [
  {
    path: "/",
    redirect: "/login",
  },
  {
    path: "/login",
    name: "Login",
    meta: {
      title: "登录",
    },
    component: () => import("@/Layout/Login"),
  },
  {
    path: "/home",
    name: "Home",
    component: () => import("@/views/Home"),
  },
  {
    path: "/regis",
    name: "Regis",
    meta: {
      title: "注册",
    },
    component: () => import("@/Layout/Regis"),
  },
  {
    path: "/search",
    redirect: "/search/0",
  },
  {
    path: "/search/:input",
    name: "Search",
    meta: {
      title: "搜索",
    },
    component: () => import("@/views/Search"),
  },
  {
    path: "/editor",
    name: "Editor",
    component: () => import("@/components/editor"),
  },
  {
    path: "/userhomepage/:username",
    name: "UserHomePage",
    meta: {
      title: "个人主页",
    },
    component: () => import("@/Layout/UserHomePage"),
  },
  {
    path: "/usersetting",
    redirect: "/userinformationsetting",
  },
  {
    path: "/usersetting",
    name: "UserSetting",
    meta: {
      title: "用户设置",
    },
    component: () => import("@/Layout/UserSetting"),
    children: [
      {
        path: "/userinformationsetting",
        name: "UserInformationSetting",
        meta: {
          title: "资料查看",
        },
        component: () =>
          import("@/views/UserSettingViews/UserInformationSetting"),
      },
      {
        path: "/usernotice",
        name: "UserNotice",
        component: () => import("@/views/UserSettingViews/UserNotice"),
      },
      {
        path: "/useraccount",
        name: "userAccount",
        meta: {
          title: "密码设置",
        },
        component: () => import("@/views/UserSettingViews/UserAccount"),
      },
      {
        path: "/usereditinformation",
        name: "userEditInformation",
        meta: {
          title: "资料设置",
        },
        component: () => import("@/views/UserSettingViews/UserEditInformation"),
      },
      {
        path: "/sshsetting",
        name: "UserSshSetting",
        meta: {
          title: "SSH密钥",
        },
        component: () => import("@/views/UserSettingViews/UserSshSetting"),
      },
    ],
  },
  {
    path: "/addhouse",
    name: "AddHouse",
    meta: {
      title: "添加仓库",
    },
    component: () => import("@/views/HouseHomePageViews/AddHouse"),
  },
  {
    path: "/househomepage/:username/:housename",
    name: "HouseHomePage",
    component: () => import("@/Layout/HouseHomePage"),
    // meta路由自身自带的属性
    meta: {
      auth: true,
      title: "仓库",
    },
    children: [
      {
        path: "housecode",
        name: "HouseCode",
        meta: {
          title: "仓库代码",
        },
        component: () => import("@/views/HouseHomePageViews/HouseCode"),
        children: [
          {
            path: ":index",
            name: "Index",
            component: () => import("@/views/HouseHomePageViews/HouseCode"),
          },
          {
            path: ":index/:index1",
            name: "Index1",
            component: () => import("@/views/HouseHomePageViews/HouseCode"),
          },
          {
            path: ":index/:index1/:index2",
            name: "Index2",
            component: () => import("@/views/HouseHomePageViews/HouseCode"),
          },
          {
            path: ":index/:index1/:index2/:index3",
            name: "Index3",
            component: () => import("@/views/HouseHomePageViews/HouseCode"),
          },
          {
            path: ":index/:index1/:index2/:index3/:index4",
            name: "Index4",
            component: () => import("@/views/HouseHomePageViews/HouseCode"),
          },
          {
            path: ":index/:index1/:index2/:index3/:index4/:index5",
            name: "Index5",
            component: () => import("@/views/HouseHomePageViews/HouseCode"),
          },
          {
            path: ":index/:index1/:index2/:index3/:index4/:index5/:index6",
            name: "Index6",
            component: () => import("@/views/HouseHomePageViews/HouseCode"),
          },
          {
            path: ":index/:index1/:index2/:index3/:index4/:index5/:index6/:index7",
            name: "Index7",
            component: () => import("@/views/HouseHomePageViews/HouseCode"),
          },
          {
            path: ":index/:index1/:index2/:index3/:index4/:index5/:index6/:index7/:index8",
            name: "Index8",
            component: () => import("@/views/HouseHomePageViews/HouseCode"),
          },
        ],
        // children:[
        //     {
        //       path: "housecode/:indexFile",
        //       name: "HouseCode",
        //       component: () => import("@/views/HouseHomePageViews/HouseCode"),
        //     },
      },
      {
        path: "showissue",
        name: "ShowIssue",
        meta: {
          title: "工单",
        },
        component: () => import("@/views/IssueViews/ShowIssue"),
      },
      {
        path: "addissue",
        name: "AddIssue",
        meta: {
          title: "新建工单",
        },
        component: () => import("@/views/IssueViews/AddIssue"),
      },
      {
        path: "editissue/:issueId",
        name: "EditIssue",
        meta: {
          title: "编辑工单",
        },
        component: () => import("@/views/IssueViews/EditIssue"),
      },
      {
        path: "viewissue/:issueId",
        name: "ViewIssue",
        meta: {
          title: "查看工单",
        },
        component: () => import("@/views/IssueViews/ViewIssue"),
      },
      {
        path: "newpullrequest",
        name: "NewPullRequest",
        meta: {
          title: "新建PR",
        },
        component: () => import("@/views/PrViews/NewPullRequest"),
      },
      {
        path: "showpullrequest",
        name: "ShowPullRequest",
        component: () => import("@/views/PrViews/ShowPullRequest"),
      },
    ],
  },
  {
    path: "/househomepage/:username/:housename/housesetting",
    name: "HouseSetting",
    meta: {
      title: "仓库设置",
    },
    component: () => import("@/Layout/HouseSetting"),
    children: [
      {
        path: "/househomepage/:username/:housename/housesetting-baseinfo",
        name: "HouseInformation",
        meta: {
          title: "仓库信息",
        },
        component: () => import("@/views/HouseSettingViews/HouseInformation"),
      },
      {
        path: "/househomepage/:username/:housename/housesetting-review",
        name: "HouseReviewSetting",
        component: () => import("@/views/HouseSettingViews/HouseReviewSetting"),
      },
      {
        path: "/househomepage/:username/:housename/housesetting-transfer",
        name: "HouseTransfer",
        meta: {
          title: "仓库转让",
        },
        component: () => import("@/views/HouseSettingViews/HouseTransfer"),
      },
      {
        path: "/househomepage/:username/:housename/housesetting-clear",
        name: "HouseClearDelete",
        meta: {
          title: "仓库删除",
        },
        component: () => import("@/views/HouseSettingViews/HouseClearDelete"),
      },
      {
        path: "/househomepage/:username/:housename/housesetting-admin",
        name: "HouseAdmin",
        meta: {
          title: "仓库管理",
        },
        component: () => import("@/views/HouseSettingViews/HouseAdmin"),
      },
      {
        path: "/househomepage/:username/:housename/housesetting-worker",
        name: "HouseWorker",
        meta: {
          title: "仓库管理",
        },
        component: () => import("@/views/HouseSettingViews/HouseWorker"),
      },
      {
        path: "/househomepage/:username/:housename/housesetting-viewer",
        name: "HouseViewer",
        meta: {
          title: "仓库管理",
        },
        component: () => import("@/views/HouseSettingViews/HouseViewer"),
      },
      {
        path: "/househomepage/:username/:housename/housesetting-add",
        name: "HouseAddTeammate",
        meta: {
          title: "仓库管理",
        },
        component: () => import("@/views/HouseSettingViews/HouseAddTeammate"),
      },
    ],
  },
  {
    path: "/:catchAll(.*)",
    name: "notfound",
    component: notfound,
  },
];
const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes,
});
// router.beforeEach((to, from, next) => {
//   let isLogin = sessionStorage.getItem("token");
//   if (!isLogin) {
//     //未登录
//     return next({ path: "/login" });
//   } else if (to.path === "/login") {
//     return next("/userhomepage/" + sessionStorage.getItem("username"));
//   }
//   next();
// });
router.beforeEach((to, from, next) => {
  /* 路由发生变化修改页面title */
  if (to.meta.title) {
    document.title = to.meta.title;
  }
  next();
});
export default router;
